﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CWB.Common.Constant;
using System.Web;
using log4net;
using CWB.Web.Models.Configuration;

namespace CWB.Web
{
    public class SessionData
    {
        public static readonly string TradingSessionKey = "_Trading";

        public Trading trading
        {
            get
            {
                return (Trading)HttpContext.Current.Session[TradingSessionKey];
            }
            set
            {
                HttpContext.Current.Session[TradingSessionKey] = value;
            }
        }

        public void Logout()
        {
            Trading ordTrading = (Trading)HttpContext.Current.Session[TradingSessionKey];
            Trading newTrading = new Trading();
            if (ordTrading != null)
            {
                newTrading.loginType = ordTrading.loginType;
            }
            if (ordTrading != null && ordTrading.languageInfo != null)
            {
                newTrading.languageInfo = ordTrading.languageInfo;
            }
            this.trading = newTrading;
        }

        public void ClearALL()
        {
            /*
            this.trading = null;
            HttpContext.Current.Session.Clear();
             * */
        }
    }

    [Serializable]
    public class Trading
    {
        public Trading() 
        {
            userName = default(string);
            sn = default(int);
            loginType = LoginType.Member;
            chk = default(string);
            logoutUrl = default(string);
            isLogined = false;
            position = 3;
        }
        public string userName { get; set; }
        public int sn { get; set; }
        public LoginType loginType { get; set; }
        public string chk { get; set; }
        public string logoutUrl { get; set; }
        public bool isLogined { get; set; }
        public int position { get; set; }
        public LanguageInfo languageInfo { get; set; }
    }
}
